#include<bits/stdc++.h>
using namespace std;
int T, m, n, L, V;
int cnt_car, cnt_p;
struct{
    int d, v, a;
}car[100005];
struct P{
    int seit, bis;
    int C;
};
int p[100005];
map<int,vector<int>> mp;
vector<P> vec;
set<int> all;

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    //freopen("./CSP-S/detect/detect3.in", "r", stdin);
    cin >> T;
    while(T--)
    {
        mp.clear();
        all.clear();
        vec.clear();
        cin >> n >> m >> L >> V;
        cnt_car = 0, cnt_p = m;
        for(int i = 1; i <= n; i++){
            int d, v, a;
            cin >> d >> v >> a;
            car[i] = {d, v, a};
        }
        for(int i = 1; i <= m; i++){
            cin >> p[i];
        }
        for(int i = 1; i <= n; i++){
            int d = car[i].d, a = car[i].a, v = car[i].v;
            if(a > 0){
                double s = min(d + max((double)(V * V - v * v) / (2 * a), 0.0), (double)L);
                for(int j = 1; j <= m; j++){
                    if(p[j] > s){
                        cnt_car++;
                        vec.push_back({j, m, i});
                        all.insert(i);
                        break;
                    }
                }
            }
            else if(a < 0){
                double s = min(d + max((double)(V * V - v * v) / (2 * a), 0.0), (double)L);
                int seit = -1, bis = -1;
                for(int j = 1; j <= m; j++){
                    if(p[j] >= d){
                        seit = j;
                        break;
                    }
                }
                for(int j = m; j >= 1; j--){
                    if(p[j] <= s){
                        bis = j;
                        break;
                    }
                }
                if(seit <= bis){
                    cnt_car++;
                    vec.push_back({seit, bis, i});
                    all.insert(i);
                }
            }
            else if(v > V){
                cnt_car++;
                for(int j = 1; j <= m; j++){
                    if(p[j] >= d){
                        vec.push_back({j, m, i});
                        all.insert(i);
                    }
                }
            }
        }
        cout << cnt_car << ' ';
        for(auto u : vec){
            for(int i = u.seit; i <= u.bis; i++)
                mp[i].push_back(u.C);
        }
        //for(auto u:all)cout<<u<<' ';
        while (all.size()){
            int maxn = -1, ptr;
            for(int i = 1; i <= m; i++){
                int cnt = 0;
                //cout << endl<<i << endl;
                for(auto u : mp[i]){
                    //cout << u <<' ';
                    for(auto uu : all){
                        if(uu == u){
                            cnt++;
                            break;
                        }
                    }
                }
                if(cnt > maxn){
                    maxn = cnt;
                    ptr = i;
                }
            }
            auto temp = mp[ptr];
            mp.erase(ptr);
            cnt_p--;
            //cout << "\nsave " << ptr << ": erase ";
            for(auto u : temp){
                //cout<<u<<" ";
                all.erase(u);
            }
        }
        cout << cnt_p << endl;
    }
    return 0;
}

